import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _dec3, _dec4, _class, _class2;

import React, { PureComponent } from 'react';
import { Button, Col, DatePicker, Form, Input, Row, Select } from 'antd';
import intl from 'utils/intl';
import Lov from 'components/Lov';
import { getDateTimeFormat } from 'utils/utils';
import moment from 'moment';
import { Bind } from 'lodash-decorators';
import { SEARCH_FORM_ROW_LAYOUT } from 'utils/constants';
var prefix = 'cpfm.login.audit.model';
var FilterForm = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec3 = Bind(), _dec4 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_PureComponent) {
  _inherits(FilterForm, _PureComponent);

  var _super = _createSuper(FilterForm);

  function FilterForm(props) {
    var _this;

    _classCallCheck(this, FilterForm);

    _this = _super.call(this, props);
    props.onRef(_assertThisInitialized(_this));
    _this.state = {
      expandForm: false,
      timeFormat: getDateTimeFormat()
    };
    return _this;
  }
  /**
   * 表单查询
   */


  _createClass(FilterForm, [{
    key: "handleSearch",
    value: function handleSearch() {
      var _this$props = this.props,
          onSearch = _this$props.onSearch,
          form = _this$props.form;

      if (onSearch) {
        form.validateFields(function (err) {
          if (!err) {
            // 如果验证成功,则执行onSearch
            onSearch();
          }
        });
      }
    }
    /**
     * 表单重置
     */

  }, {
    key: "handleFormReset",
    value: function handleFormReset() {
      this.props.form.resetFields();
    } // 查询条件展开/收起

  }, {
    key: "toggleForm",
    value: function toggleForm() {
      var expandForm = this.state.expandForm;
      this.setState({
        expandForm: !expandForm
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          form = _this$props2.form,
          typeList = _this$props2.typeList;
      var _this$state = this.state,
          expandForm = _this$state.expandForm,
          timeFormat = _this$state.timeFormat;
      var formItemLayout = {
        labelCol: {
          span: 10
        },
        wrapperCol: {
          span: 14
        }
      };
      var getFieldDecorator = form.getFieldDecorator,
          getFieldValue = form.getFieldValue,
          setFieldsValue = form.setFieldsValue,
          registerField = form.registerField;
      return /*#__PURE__*/React.createElement("div", {
        className: "table-list-search"
      }, /*#__PURE__*/React.createElement(Form, {
        className: "more-fields-search-form"
      }, /*#__PURE__*/React.createElement(Row, Object.assign({
        type: "flex",
        align: "bottom",
        gutter: 24
      }, SEARCH_FORM_ROW_LAYOUT), /*#__PURE__*/React.createElement(Col, {
        span: 6
      }, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, formItemLayout, {
        label: intl.get("".concat(prefix, ".auditTypeMeaning")).d('审计类型')
      }), getFieldDecorator('auditType')( /*#__PURE__*/React.createElement(Select, {
        allowClear: true
      }, typeList.map(function (item) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          value: item.value,
          key: item.value
        }, item.meaning);
      }))))), /*#__PURE__*/React.createElement(Col, {
        span: 6
      }, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, formItemLayout, {
        label: intl.get("".concat(prefix, ".account")).d('账号')
      }), getFieldDecorator('loginName', {})( /*#__PURE__*/React.createElement(Input, {
        trim: true,
        inputChinese: false
      })))), /*#__PURE__*/React.createElement(Col, {
        span: 6
      }, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, formItemLayout, {
        label: intl.get("".concat(prefix, ".userName")).d('名称')
      }), getFieldDecorator('userName', {})( /*#__PURE__*/React.createElement(Input, {
        trim: true
      })))), /*#__PURE__*/React.createElement(Col, {
        span: 6,
        className: "search-btn-more"
      }, /*#__PURE__*/React.createElement(Form.Item, null, /*#__PURE__*/React.createElement(Button, {
        onClick: this.toggleForm
      }, expandForm ? intl.get('cpaas.common.button.collected').d('收起查询') : intl.get("cpaas.common.button.viewMore").d('更多查询')), /*#__PURE__*/React.createElement(Button, {
        "data-code": "reset",
        onClick: this.handleFormReset
      }, intl.get('cpaas.common.button.reset').d('重置')), /*#__PURE__*/React.createElement(Button, {
        "data-code": "search",
        type: "primary",
        htmlType: "submit",
        onClick: this.handleSearch
      }, intl.get('cpaas.common.button.search').d('查询'))))), /*#__PURE__*/React.createElement(Row, Object.assign({
        style: {
          display: expandForm ? '' : 'none'
        }
      }, SEARCH_FORM_ROW_LAYOUT), /*#__PURE__*/React.createElement(Col, {
        span: 6
      }, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, formItemLayout, {
        label: intl.get("".concat(prefix, ".phone")).d('手机号')
      }), getFieldDecorator('phone', {})( /*#__PURE__*/React.createElement(Input, {
        trim: true,
        inputChinese: false
      })))), /*#__PURE__*/React.createElement(Col, {
        span: 6
      }, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, formItemLayout, {
        label: intl.get("".concat(prefix, ".tenant")).d('所属租户')
      }), getFieldDecorator('tenantName', {})( /*#__PURE__*/React.createElement(Lov, {
        code: "CPFM.TENANT",
        onChange: function onChange(val, record) {
          registerField('tenantId');
          setFieldsValue({
            tenantId: record.tenantId
          });
        },
        textValue: getFieldValue('tenantName')
      })))), /*#__PURE__*/React.createElement(Col, {
        span: 6
      }, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, formItemLayout, {
        label: intl.get("".concat(prefix, ".login.time.after")).d('登录时间从')
      }), getFieldDecorator('loginDateAfter')( /*#__PURE__*/React.createElement(DatePicker, {
        showTime: true,
        placeholder: "",
        format: timeFormat,
        disabledDate: function disabledDate(currentDate) {
          return getFieldValue('loginDateBefore') && moment(getFieldValue('loginDateBefore')).isBefore(currentDate, 'second');
        }
      }))))), /*#__PURE__*/React.createElement(Row, Object.assign({
        style: {
          display: expandForm ? '' : 'none'
        }
      }, SEARCH_FORM_ROW_LAYOUT), /*#__PURE__*/React.createElement(Col, {
        span: 6
      }, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, formItemLayout, {
        label: intl.get("".concat(prefix, ".login.time.before")).d('登录时间至')
      }), getFieldDecorator('loginDateBefore')( /*#__PURE__*/React.createElement(DatePicker, {
        showTime: true,
        placeholder: "",
        format: timeFormat,
        disabledDate: function disabledDate(currentDate) {
          return getFieldValue('loginDateAfter') && moment(getFieldValue('loginDateAfter')).isAfter(currentDate, 'second');
        }
      })))))));
    }
  }]);

  return FilterForm;
}(PureComponent), (_applyDecoratedDescriptor(_class2.prototype, "handleSearch", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "handleSearch"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleFormReset", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "handleFormReset"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "toggleForm", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "toggleForm"), _class2.prototype)), _class2)) || _class);
export { FilterForm as default };